package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.Combat;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 倾国倾城<br/>
 * 对敌方全员释放魅惑攻击，造成{0}%技能伤害，同时对每个命中的目标都有{1}%几率令对方混乱
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90120 extends CombatSkill {

	public COMBAT_SKILL_90120(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
//		CombatUnit source = action.unit;
		float magicPowerRate = skill.getParameter(0) / GameStaticConfig.percentBase;
		int chaosProbability = (int) skill.getParameter(1);
		List<CombatUnit> targets = action.target.all();
		for (int i = 0; i < targets.size(); i++) {
			CombatUnit target = targets.get(i);
			if (!target.isDied()) {
				ActionEffect eff = action.addTarget(target);
				CombatUtils.calcMagicAttack(eff, magicPowerRate);
				if (eff.isHit() && Combat.RND.nextInt(GameStaticConfig.percentBase) < chaosProbability) {
					action.addBuff(new BUFF(skill, target));
				}
			}
		}
	}
	
	// 魅惑
	static class BUFF extends CombatBuff {
		public BUFF(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(), owner);
		}
		@Override
		public CombatUnit preTarget(Action action) {
			active = true;
			CombatUnit target = action.ref().ref().getUnitRandomly();
			return target;
		}
		@Override
		@JSONField(serialize = false)
		public boolean isDebuff() {
			return true;
		}
	}

}
